{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "brave-daughter",
   "metadata": {},
   "source": [
    "# Scheduler Local Test\n",
    "\n",
    "\n",
    "## Setup\n",
    "\n",
    "\n",
    "* `make start-scheduler` \n",
    "* `make start-envoy`\n",
    "* `make start-agent`\n",
    "* `make start-mlserver`\n",
    "* `make start-rclone`"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "amazing-baker",
   "metadata": {},
   "source": [
    "## No Auth Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "black-playlist",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "integral-stress",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"serverName\": \"mlserver\",\r\n",
      "  \"resources\": [\r\n",
      "    {\r\n",
      "      \"totalMemoryBytes\": \"1000000\",\r\n",
      "      \"availableMemoryBytes\": \"1199500\",\r\n",
      "      \"numLoadedModels\": 1,\r\n",
      "      \"overCommitPercentage\": 20\r\n",
      "    }\r\n",
      "  ],\r\n",
      "  \"expectedReplicas\": -1,\r\n",
      "  \"availableReplicas\": 1,\r\n",
      "  \"numLoadedModelReplicas\": 1\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "constitutional-appliance",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*   Trying 0.0.0.0...\n",
      "* Connected to 0.0.0.0 (127.0.0.1) port 9000 (#0)\n",
      "> POST /v2/models/iris/infer HTTP/1.1\n",
      "> Host: 0.0.0.0:9000\n",
      "> User-Agent: curl/7.47.0\n",
      "> Accept: */*\n",
      "> Content-Type: application/json\n",
      "> seldon-model: iris\n",
      "> Content-Length: 94\n",
      "> \n",
      "* upload completely sent off: 94 out of 94 bytes\n",
      "< HTTP/1.1 200 OK\n",
      "< content-length: 196\n",
      "< content-type: application/json\n",
      "< date: Sat, 02 Apr 2022 07:45:51 GMT\n",
      "< server: envoy\n",
      "< x-envoy-upstream-service-time: 1039\n",
      "< seldon-route: iris_1\n",
      "< \n",
      "* Connection #0 to host 0.0.0.0 left intact\n",
      "{\"model_name\":\"iris_1\",\"model_version\":\"1\",\"id\":\"41656083-ed34-49b3-b122-65be1d5a52bb\",\"parameters\":null,\"outputs\":[{\"name\":\"predict\",\"shape\":[1],\"datatype\":\"INT64\",\"parameters\":null,\"data\":[2]}]}"
     ]
    }
   ],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "unable-oregon",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*   Trying 0.0.0.0...\r\n",
      "* Connected to 0.0.0.0 (127.0.0.1) port 9000 (#0)\r\n",
      "> GET /v2/health/live HTTP/1.1\r",
      "\r\n",
      "> Host: 0.0.0.0:9000\r",
      "\r\n",
      "> User-Agent: curl/7.47.0\r",
      "\r\n",
      "> Accept: */*\r",
      "\r\n",
      "> seldon-model: iris\r",
      "\r\n",
      "> \r",
      "\r\n",
      "< HTTP/1.1 200 OK\r",
      "\r\n",
      "< date: Sat, 02 Apr 2022 07:45:51 GMT\r",
      "\r\n",
      "< server: envoy\r",
      "\r\n",
      "< x-envoy-upstream-service-time: 1\r",
      "\r\n",
      "< seldon-route: iris_1\r",
      "\r\n",
      "< transfer-encoding: chunked\r",
      "\r\n",
      "< \r",
      "\r\n",
      "* Connection #0 to host 0.0.0.0 left intact\r\n"
     ]
    }
   ],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/health/live -H \"seldon-model: iris\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "advance-smoke",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*   Trying 0.0.0.0...\r\n",
      "* Connected to 0.0.0.0 (127.0.0.1) port 9000 (#0)\r\n",
      "> GET /v2/models/iris HTTP/1.1\r",
      "\r\n",
      "> Host: 0.0.0.0:9000\r",
      "\r\n",
      "> User-Agent: curl/7.47.0\r",
      "\r\n",
      "> Accept: */*\r",
      "\r\n",
      "> seldon-model: iris\r",
      "\r\n",
      "> \r",
      "\r\n",
      "< HTTP/1.1 200 OK\r",
      "\r\n",
      "< content-length: 105\r",
      "\r\n",
      "< content-type: application/json\r",
      "\r\n",
      "< date: Sat, 02 Apr 2022 07:45:51 GMT\r",
      "\r\n",
      "< server: envoy\r",
      "\r\n",
      "< x-envoy-upstream-service-time: 2\r",
      "\r\n",
      "< seldon-route: iris_1\r",
      "\r\n",
      "< \r",
      "\r\n",
      "* Connection #0 to host 0.0.0.0 left intact\r\n",
      "{\"name\":\"iris_1\",\"versions\":[],\"platform\":\"\",\"inputs\":[],\"outputs\":[],\"parameters\":{\"content_type\":null}}"
     ]
    }
   ],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris -H \"seldon-model: iris\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "eight-madrid",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris_1\",\r\n",
      "  \"modelVersion\": \"1\",\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"predict\",\r\n",
      "      \"datatype\": \"INT64\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"int64Contents\": [\r\n",
      "          \"2\"\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "    -plaintext \\\n",
    "    -import-path ../../apis \\\n",
    "    -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "    -rpc-header seldon-model:iris \\\n",
    "    0.0.0.0:9000 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "refined-plymouth",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris\",\r\n",
      "  \"versions\": [\r\n",
      "    {\r\n",
      "      \"version\": 1,\r\n",
      "      \"serverName\": \"mlserver\",\r\n",
      "      \"modelReplicaState\": {\r\n",
      "        \"0\": {\r\n",
      "          \"state\": \"Available\",\r\n",
      "          \"lastChangeTimestamp\": \"2022-04-02T07:45:42.800774356Z\"\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"state\": {\r\n",
      "        \"state\": \"ModelAvailable\",\r\n",
      "        \"availableReplicas\": 1,\r\n",
      "        \"lastChangeTimestamp\": \"2022-04-02T07:45:42.800774356Z\"\r\n",
      "      },\r\n",
      "      \"modelDefn\": {\r\n",
      "        \"meta\": {\r\n",
      "          \"name\": \"iris\"\r\n",
      "        },\r\n",
      "        \"modelSpec\": {\r\n",
      "          \"uri\": \"gs://seldon-models/mlserver/iris\",\r\n",
      "          \"requirements\": [\r\n",
      "            \"sklearn\"\r\n",
      "          ],\r\n",
      "          \"memoryBytes\": \"500\"\r\n",
      "        },\r\n",
      "        \"deploymentSpec\": {\r\n",
      "          \"replicas\": 1\r\n",
      "        }\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "rolled-london",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"serverName\": \"mlserver\",\r\n",
      "  \"resources\": [\r\n",
      "    {\r\n",
      "      \"totalMemoryBytes\": \"1000000\",\r\n",
      "      \"availableMemoryBytes\": \"1199500\",\r\n",
      "      \"numLoadedModels\": 1,\r\n",
      "      \"overCommitPercentage\": 20\r\n",
      "    }\r\n",
      "  ],\r\n",
      "  \"expectedReplicas\": -1,\r\n",
      "  \"availableReplicas\": 1,\r\n",
      "  \"numLoadedModelReplicas\": 1\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "computational-gross",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "attempted-chocolate",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris\",\r\n",
      "  \"versions\": [\r\n",
      "    {\r\n",
      "      \"version\": 1,\r\n",
      "      \"serverName\": \"mlserver\",\r\n",
      "      \"modelReplicaState\": {\r\n",
      "        \"0\": {\r\n",
      "          \"state\": \"Unloaded\",\r\n",
      "          \"lastChangeTimestamp\": \"2022-04-02T07:46:13.974650008Z\"\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"state\": {\r\n",
      "        \"state\": \"ModelTerminated\",\r\n",
      "        \"lastChangeTimestamp\": \"2022-04-02T07:46:13.974650008Z\"\r\n",
      "      },\r\n",
      "      \"modelDefn\": {\r\n",
      "        \"meta\": {\r\n",
      "          \"name\": \"iris\"\r\n",
      "        },\r\n",
      "        \"modelSpec\": {\r\n",
      "          \"uri\": \"gs://seldon-models/mlserver/iris\",\r\n",
      "          \"requirements\": [\r\n",
      "            \"sklearn\"\r\n",
      "          ],\r\n",
      "          \"memoryBytes\": \"500\"\r\n",
      "        },\r\n",
      "        \"deploymentSpec\": {\r\n",
      "          \"replicas\": 1\r\n",
      "        }\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ],\r\n",
      "  \"deleted\": true\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "offensive-begin",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"serverName\": \"mlserver\",\r\n",
      "  \"resources\": [\r\n",
      "    {\r\n",
      "      \"totalMemoryBytes\": \"1000000\",\r\n",
      "      \"availableMemoryBytes\": \"1200000\",\r\n",
      "      \"overCommitPercentage\": 20\r\n",
      "    }\r\n",
      "  ],\r\n",
      "  \"expectedReplicas\": -1,\r\n",
      "  \"availableReplicas\": 1\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "ruled-baltimore",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "*   Trying 0.0.0.0...\r\n",
      "* Connected to 0.0.0.0 (127.0.0.1) port 9000 (#0)\r\n",
      "> POST /v2/models/iris/infer HTTP/1.1\r",
      "\r\n",
      "> Host: 0.0.0.0:9000\r",
      "\r\n",
      "> User-Agent: curl/7.47.0\r",
      "\r\n",
      "> Accept: */*\r",
      "\r\n",
      "> Content-Type: application/json\r",
      "\r\n",
      "> seldon-model: iris\r",
      "\r\n",
      "> Content-Length: 94\r",
      "\r\n",
      "> \r",
      "\r\n",
      "* upload completely sent off: 94 out of 94 bytes\r\n",
      "< HTTP/1.1 404 Not Found\r",
      "\r\n",
      "< date: Sat, 02 Apr 2022 07:46:23 GMT\r",
      "\r\n",
      "< server: envoy\r",
      "\r\n",
      "< connection: close\r",
      "\r\n",
      "< content-length: 0\r",
      "\r\n",
      "< \r",
      "\r\n",
      "* Closing connection 0\r\n"
     ]
    }
   ],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "smart-appendix",
   "metadata": {},
   "source": [
    "## Inline RClone Config Example\n",
    "\n",
    "Before running this \n",
    "  * install minio in a kind cluster with Ansible.\n",
    "  * Update ip address for exposed minio ip address in example below\n",
    "  \n",
    "Create rclone.conf changing the ip address for minio as appropriate\n",
    "\n",
    "```\n",
    "[s3]\n",
    "type = s3\n",
    "provider = minio\n",
    "env_auth = false\n",
    "access_key_id = minioadmin\n",
    "secret_access_key = minioadmin\n",
    "endpoint = http://172.18.255.1:9000\n",
    "```\n",
    "  \n",
    " Copy iris model to minio\n",
    " \n",
    " ```\n",
    " rclone --config ./rclone.conf copy mlrepo/iris s3://test\n",
    " ```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "shaped-thursday",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl --format text -d '\\\n",
    "         model { \\\n",
    "            meta: { name:\"iris\"},\\\n",
    "            modelSpec: {uri:\"s3://models/iris\",\\\n",
    "                        storageConfig: { \\\n",
    "                        storageRcloneConfig: \"{\\\"type\\\":\\\"s3\\\",\\\"name\\\":\\\"s3\\\",\\\"parameters\\\":{\\\"provider\\\":\\\"minio\\\",\\\"env_auth\\\":\\\"false\\\",\\\"access_key_id\\\":\\\"minioadmin\\\",\\\"secret_access_key\\\":\\\"minioadmin\\\",\\\"endpoint\\\":\\\"http://172.18.255.2:9000\\\"}}\" \\\n",
    "     } \\\n",
    "                        requirements:[\"sklearn\"],\\\n",
    "                        memoryBytes:500},\\\n",
    "            deploymentSpec:{replicas:1}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "macro-sweden",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "detected-booking",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "sound-kitchen",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "chronic-elder",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "        0.0.0.0:9000 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "stupid-banks",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "willing-account",
   "metadata": {},
   "source": [
    "## Multiple Version Example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "daily-equipment",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris-multi-version\",\\\n",
    "                           \"artifactVersion\":1,\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "super-ordinance",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "surface-spelling",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "experimental-flash",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris-multi-version\",\\\n",
    "                           \"artifactVersion\":2,\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "colored-hybrid",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dense-curtis",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "posted-slave",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "        -plaintext \\\n",
    "        -import-path ../../apis \\\n",
    "        -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "        -rpc-header seldon-model:iris \\\n",
    "        0.0.0.0:9000 inference.GRPCInferenceService/ModelInfer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "prostate-plate",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris\",\r\n",
      "  \"versions\": [\r\n",
      "    {\r\n",
      "      \"version\": 1,\r\n",
      "      \"serverName\": \"mlserver\",\r\n",
      "      \"kubernetesMeta\": {\r\n",
      "        \"namespace\": \"seldon-mesh\"\r\n",
      "      },\r\n",
      "      \"modelReplicaState\": {\r\n",
      "        \"0\": {\r\n",
      "          \"state\": \"Available\",\r\n",
      "          \"lastChangeTimestamp\": \"2022-04-01T12:44:19.592467897Z\"\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"state\": {\r\n",
      "        \"state\": \"ModelAvailable\",\r\n",
      "        \"availableReplicas\": 1,\r\n",
      "        \"lastChangeTimestamp\": \"2022-04-01T12:44:19.592467897Z\"\r\n",
      "      },\r\n",
      "      \"modelDefn\": {\r\n",
      "        \"meta\": {\r\n",
      "          \"name\": \"iris\",\r\n",
      "          \"kubernetesMeta\": {\r\n",
      "            \"namespace\": \"seldon-mesh\"\r\n",
      "          }\r\n",
      "        },\r\n",
      "        \"modelSpec\": {\r\n",
      "          \"uri\": \"gs://seldon-models/mlserver/iris\",\r\n",
      "          \"requirements\": [\r\n",
      "            \"sklearn\"\r\n",
      "          ]\r\n",
      "        },\r\n",
      "        \"deploymentSpec\": {\r\n",
      "          \"replicas\": 1,\r\n",
      "          \"minReplicas\": 1\r\n",
      "        }\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"},\"allVersions\":true}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "postal-detail",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "conditional-joining",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ModelStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "nominated-ideal",
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "senior-information",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!curl -v http://0.0.0.0:9000/v2/models/iris/infer -H \"Content-Type: application/json\" -H \"seldon-model: iris\"\\\n",
    "        -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "south-abuse",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
